/* GUI CONVERTED from sqqomta1.p (converter v1.76) Wed May 22 11:23:45 2002 */
/* sqqomta1.p - QUOTE MAINTENANCE                                             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.8.1.8 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 8.5      LAST MODIFIED: 05/24/96   BY: gwm *J0NF*                */
/* REVISION: 8.5      LAST MODIFIED: 06/03/96   BY: DAH *J0N2*                */
/* REVISION: 8.5      LAST MODIFIED: 07/17/96   BY: taf *J0ZH*                */
/* REVISION: 8.5      LAST MODIFIED: 07/26/96   BY: taf *J11Y*                */
/* REVISION: 8.6      LAST MODIFIED: 06/06/97   BY: *K0DQ* Taek-Soo Chang     */
/* REVISION: 8.6      LAST MODIFIED: 01/13/98   BY: *J29R* Aruna Patil        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/11/98   BY: *J2L3* Niranjan R.        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Patti Gaultney     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/18/00   BY: *M0SP* Santosh Rao        */
/* REVISION: 9.1      LAST MODIFIED: 11/20/00   BY: *N0TW* Jean Miller        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.8.1.7       BY: Katie Hilbert     DATE: 04/01/01  ECO: *P002*  */
/* $Revision: 1.8.1.8 $    BY: Jean Miller       DATE: 05/15/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* Revision: EB2 SP3       BY: Kaine Zhang        DATE: 10/31/03  *hk-s-026** */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* OUTPUT PARAMETERS */
/* NO-UNDO NEEDED BECAUSE WE NEED TO RETAIN THESE VALUES */
/* WHEN PROCESSING REQUIRES A TRANSACTION TO BE UNDONE   */
define output parameter undomain      as logical no-undo.
define output parameter next_undomain as logical no-undo.
define output parameter nextmain      as logical no-undo.

define new shared variable l_edittax  like  mfc_logical initial no no-undo.

/* SHARED VARIABLES */
define shared variable qonbr like qo_nbr.
define shared variable new_order like mfc_logical.
define shared variable qocmmts like mfc_logical initial yes label "Comments".
define shared variable old_ft_type like ft_type.
define shared variable rsn_lost like qod_rsn_lost.
define shared variable mult_slspsn like mfc_logical no-undo.
define shared variable qo_recno as recid.
define shared variable undo_cust like mfc_logical.
define shared variable picust like cm_addr.
define shared variable line_pricing like pic_qo_linpri label "Line Pricing".
define shared variable del-yn like mfc_logical.
define shared variable qocrt_int like qod_crt_int.
define shared variable tax_in like cm_tax_in.
define shared variable reprice like mfc_logical label "Reprice".
define shared variable promise_date as date label "Promise Date".
define shared variable calc_fr like mfc_logical label "Calc Freight".
define shared variable disp_fr like mfc_logical label "Display Weights".
define shared variable balance_fmt as character.
define shared variable limit_fmt as character.
define shared variable undo_flag like mfc_logical.
define shared variable oldcurr like qo_curr.
define shared variable rndmthd like rnd_rnd_mthd.
define shared variable prepaid_fmt as character no-undo.
define shared variable cm_recno as recid.
define shared variable prepaid_old as character no-undo.
define shared variable ad_recno as recid.
define shared variable qotax_trl like tax_trl.
define shared variable tax_recno as recid.
define shared variable cmtindx like cmt_indx.
define shared variable line like qod_line.

{sqcurvar.i}

/* LOCAL VARIABLES */
define variable counter as integer no-undo.
define variable l_old_shipto    like so_ship no-undo.
define variable l_qo_fix_pr     like mfc_logical no-undo.
define variable msg-arg         as character format "x(16)" no-undo.

/* SHARED FRAME DEFINITIONS */
define shared frame a.
define shared frame b.
define shared frame sold_to.
define shared frame ship_to.

/* BUFFERS */
define buffer bill_cm for cm_mstr.

{sqqomt02.i} /* FRAMES A,B, AND B1 */

{mfadform.i "sold_to" 1 SOLD-TO}
/*V8+*/
      {mfadform.i "ship_to" "41" SHIP-TO}   

do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


   find first pic_ctrl no-lock.
   find first gl_ctrl no-lock.
   find first soc_ctrl no-lock.

   old_ft_type = "".

   find qo_mstr where qo_nbr = qonbr exclusive-lock no-error.

   if not available qo_mstr then do:

      find first qoc_ctrl no-lock.

      clear frame sold_to.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame sold_to = F-sold_to-title.
      clear frame ship_to.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame ship_to = F-ship_to-title.
      clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.

      /* Adding new record */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

      create qo_mstr.
      assign
         qo_nbr       = qonbr
         qo_ord_date  = today
         qo_exp_date  = today + qoc_days
         qo_fob       = qoc_fob
         qo_print_qo  = qoc_print
         rsn_lost     = " "
         l_qo_fix_pr  = yes
         qo_userid    = global_userid
         qocmmts      = qoc_hcmmts.

      if recid(qo_mstr) = -1 then .
      new_order = yes.

   end.

   else do:
      if qo__qad03 = 2 then
         assign l_qo_fix_pr = yes.
      else
      if qo__qad03 = 1 then
         assign l_qo_fix_pr = no.
      else
      if qo__qad03 = 0 then
         assign l_qo_fix_pr = qo_fix_rate.

      {gprun.i ""gpsiver.p""
         "(input qo_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if return_int = 0 then do:

         display
            qo_nbr qo_cust qo_bill qo_ship
         with frame a.

         /* Display qo_ord_date, etc in frame b */
         {sqqomtdi.i}

         /* User does not have access to this site  */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}

         undomain = true.
         return.

      end.

      {pxmsg.i &MSGNUM=10 &ERRORLEVEL=1}
      {mfaddisp.i qo_cust sold_to}

      if not available ad_mstr then do:
         hide message no-pause.
         {pxmsg.i &MSGNUM=3 &ERRORLEVEL=2}
      end.

      {mfaddisp.i qo_ship ship_to}

      new_order = no.
      qocmmts   = (qo_cmtindx <> 0).

      find ft_mstr where ft_terms = qo_fr_terms no-lock no-error.
      if available ft_mstr then
         old_ft_type = ft_type.
   end.

   recno = recid(qo_mstr).

   display
      qo_nbr qo_cust qo_bill qo_ship
   with frame a.

   find first qod_det where qod_nbr = qo_nbr no-lock no-error.
   if available qod_det then
      rsn_lost = qod_rsn_lost.
   else
      rsn_lost = " ".

   if qo_slspsn[2] <> "" or
      qo_slspsn[3] <> "" or
      qo_slspsn[4] <> "" then
      mult_slspsn = true.
   else
      mult_slspsn = false.

   {sqqomtdi.i} /* display qo_ord_date, etc in frame b */

   l_old_shipto = qo_ship.

   /* GET SOLD-TO, BILL-TO, AND SHIP-TO CUSTOMER */
   qo_recno = recid(qo_mstr).
   undo_cust = true.

   {gprun.i ""sqqomtcm.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   if undo_cust then do:
      undomain = true.
      /* MUST UNDO CURRENT TRANSACTION */
      undo, return.
   end.

   /* SHIP-TO CHANGED; UPDATE TAX DATA ON CONFIRMATION. PREVIOUS */
   /* HEADER TAX ENVIRONMENT BLANKED OUT FOR RECALCULATION LATER */
   l_edittax = no.

   if not batchrun and
      l_old_shipto <> "" and
      l_old_shipto <> qo_ship
   then do:

      /* SHIP-TO CHANGED; UPDATE TAX DATA? */
      {pxmsg.i &MSGNUM=2351 &ERRORLEVEL=1 &CONFIRM=l_edittax }

      if l_edittax then do:
         /* LOAD DEFAULT TAX CLASS & USAGE */
         find ad_mstr where ad_addr = qo_ship no-lock no-error.
         if not available ad_mstr then
            find ad_mstr where ad_addr = qo_cust no-lock no-error.
         if available ad_mstr then
            assign
               qo_taxable   = ad_taxable
               qo_tax_usage = ad_tax_usage
               qo_taxc = ad_taxc.
         qo_tax_env = "".
      end.  /* IF l_edittax IS TRUE */

   end. /* IF SHIP-TO CHANGED IN GTM AND NOT BATCHRUN */

   find cm_mstr where cm_mstr.cm_addr = qo_cust no-lock.
   find bill_cm where bill_cm.cm_addr = qo_bill no-lock.
   find ad_mstr where ad_addr = qo_ship  no-lock.

   cm_recno = recid(bill_cm).
   ad_recno = recid(ad_mstr).

   /*SET CUSTOMER VARIABLE USED BY PRICING ROUTINE gppibx.p*/
   picust = qo_cust.

   if qo_cust <> qo_ship and
      can-find(cm_mstr where cm_mstr.cm_addr = qo_ship)
   then
      picust = qo_ship.

   if new_order then
      line_pricing = pic_qo_linpri.
   else
      line_pricing = no.

   ststatus = stline[2].
   status input ststatus.
   del-yn = no.

   if new qo_mstr then do:

      /* SET DEFAULTS WHEN CREATING A NEW ORDER - */
      /* USE SHIP-TO CUSTOMER INFO FOR DEFAULT IF */
      /* AVAILABLE ELSE USE SOLD-TO INFO          */
      if qo_cust <> qo_ship and
         can-find(cm_mstr where cm_mstr.cm_addr = qo_ship)
      then
         find cm_mstr where cm_mstr.cm_addr = qo_ship no-lock.

      assign
         qo_cr_terms = bill_cm.cm_cr_terms
         qo_curr     = bill_cm.cm_curr
         l_qo_fix_pr = cm_mstr.cm_fix_pr
         qo_disc_pct = cm_mstr.cm_disc_pct
         qo_shipvia  = cm_mstr.cm_shipvia
         qo_partial  = cm_mstr.cm_partial
         qo_rmks     = cm_mstr.cm_rmks
         qo_site     = cm_mstr.cm_site
         qo_taxable  = cm_mstr.cm_taxable
         qo_taxc     = cm_mstr.cm_taxc
         qo_pst      = cm_mstr.cm_pst
         qo_fst_id   = cm_mstr.cm_fst_id
         qo_pst_id   = ad_pst_id   /*ship-to*/
         qo_lang     = ad_lang
         qo_fr_list   = cm_mstr.cm_fr_list
         qo_fr_terms  = cm_mstr.cm_fr_terms
         qo_fr_min_wt = cm_mstr.cm_fr_min_wt
         qo_slspsn[1] = cm_mstr.cm_slspsn[1]
         qo_slspsn[2] = cm_mstr.cm_slspsn[2]
         qo_slspsn[3] = cm_mstr.cm_slspsn[3]
         qo_slspsn[4] = cm_mstr.cm_slspsn[4] .

      {gprun.i ""gpsiver.p""
         "(input qo_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if return_int = 0 then do:
         /* User does not have access to default site # */
         {pxmsg.i &MSGNUM=2711 &ERRORLEVEL=2 &MSGARG1=qo_site}
         qo_site = "".
         display qo_site with frame b.
      end.

      /* GET DEFAULT TERMS INTEREST FOR ORDER */
      qocrt_int = 0.
      if qo_cr_terms <> "" then do:
         find ct_mstr where ct_code = qo_cr_terms no-lock no-error.
         if available ct_mstr then qocrt_int = ct_terms_int.
      end.

      /* LOAD DEFAULT TAX CLASS & USAGE */
      find ad_mstr where ad_addr = qo_ship no-lock no-error.
      if not available ad_mstr then
         find ad_mstr where ad_addr = qo_cust no-lock no-error.
      if available ad_mstr then
      assign
         qo_taxable   = ad_taxable
         qo_tax_usage = ad_tax_usage
         qo_taxc      = ad_taxc.
      ad_recno = recid(ad_mstr).

      /* Display qo_fr_list with frame b. */
      do counter = 1 to 4:

         find sp_mstr where sp_addr = cm_mstr.cm_slspsn[counter]
         no-lock no-error.

         find spd_det where
            spd_addr = cm_mstr.cm_slspsn[counter] and
            spd_prod_ln = "" and
            spd_part = "" and
            spd_cust = cm_mstr.cm_addr
         no-lock no-error.

         if available spd_det then
            qo_comm_pct[counter] = spd_comm_pct.
         else if available sp_mstr then
            qo_comm_pct[counter] = sp_comm_pct.
      end.

      if bill_cm.cm_ar_acct <> "" then
         assign
            qo_ar_acct = bill_cm.cm_ar_acct
            qo_ar_sub  = bill_cm.cm_ar_sub
            qo_ar_cc   = bill_cm.cm_ar_cc.
      else
         assign
            qo_ar_acct = gl_ar_acct
            qo_ar_sub  = gl_ar_sub
            qo_ar_cc   = gl_ar_cc.

   end.  /* new qo_mstr */

   /* LOAD DEFAULT TAX CLASS & USAGE */
   find ad_mstr where ad_addr = qo_ship no-lock no-error.
   if not available ad_mstr then
      find ad_mstr where ad_addr = qo_cust no-lock no-error.
   if available(ad_mstr) then
      tax_in  = ad_tax_in.
   ad_recno = recid(ad_mstr).

   /* CHECK CREDIT LIMIT */
   if bill_cm.cm_cr_limit < bill_cm.cm_balance then do:
      /* Customer Balance */
      msg-arg = string(bill_cm.cm_balance,balance_fmt).
      {pxmsg.i &MSGNUM=615 &ERRORLEVEL=2 &MSGARG1=msg-arg}
      /* Credit Limit */
      msg-arg = string(bill_cm.cm_cr_limit,limit_fmt).
      {pxmsg.i &MSGNUM=617 &ERRORLEVEL=1 &MSGARG1=msg-arg}
      if qo_stat = "" and soc_cr_hold then do:
         /* Quote placed on credit hold */
         {pxmsg.i &MSGNUM=690 &ERRORLEVEL=1 &MSGARG1=getTermLabel(""QUOTE"",10)}
         /* Quote placed on credit hold */
         qo_stat = "HD".
      end.
   end.

   /* CHECK CREDIT HOLD  */
   if bill_cm.cm_cr_hold  then do:
      {pxmsg.i  &MSGNUM=614 &ERRORLEVEL=2 }
      qo_stat = "HD".
   end.

   if qo_slspsn[2] <> "" or
      qo_slspsn[3] <> "" or
      qo_slspsn[4] <> ""
   then
      mult_slspsn = true.
   else
      mult_slspsn = false.

   {sqqomtdi.i} /* display qo_ord_date, etc in frame b */

   undo_flag = true.
/*hk-s-026*   {gprun.i ""sqqomtp.p""}  */
/*hk-s-026*/  {gprun.i ""xxsqqomtp.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* If undo_flag then next mainloop. */
   /* Jump out if QO was (successfully) deleted */
   if not can-find(qo_mstr where qo_nbr = input qo_nbr)
   then do:
      nextmain = true.
      return.
      /* next mainloop. */
   end.

   if undo_flag then do:
      next_undomain = true.
      undo, return.
   end.

   if (oldcurr <> qo_curr) or (oldcurr = "") then do:
      /* SET CURRENCY DEPENDENT FORMATS */
      {sqcurfmt.i}
      /* SET CURRENCY DEPENDENT FORMAT FOR PREPAID */
      prepaid_fmt = prepaid_old.
      {gprun.i ""gpcurfmt.p"" "(input-output prepaid_fmt,
                     input rndmthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      oldcurr = qo_curr.
   end.

   if qo_pricing_dt = ? then do:
      if pic_qo_date = "ord_date" then
         qo_pricing_dt = qo_ord_date.
      else
      if pic_qo_date = "req_date" then
         qo_pricing_dt = qo_req_date.
      else
      if pic_qo_date = "per_date" then
         qo_pricing_dt = promise_date.
      else
      if pic_qo_date = "due_date" then
         qo_pricing_dt = qo_due_date.
      else
         qo_pricing_dt = today.
   end.

   /* Assign next automatic number for new ship-to customer */
   if qo_ship = "qadtemp" + mfguser then do:

      find ad_mstr where ad_addr = qo_ship exclusive-lock.

      {mfactrl.i cmc_ctrl cmc_nbr ad_mstr ad_addr qo_ship}

      create ls_mstr.
      assign
         ad_addr = qo_ship
         ls_type = "ship-to"
         ls_addr = qo_ship.

      if recid(ls_mstr) = -1 then .

      /* Ship to created */
      {pxmsg.i &MSGNUM=638 &ERRORLEVEL=1 &MSGARG1=qo_ship}
      display qo_ship with frame a.
      ad_recno = recid(ad_mstr).

   end.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* TRANSACTION */

/* DETAIL */
do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


   find qo_mstr where recid(qo_mstr) = qo_recno exclusive-lock.

   /* UPDATE DUE DATE */
   for each qod_det where qod_nbr = qo_nbr:
      if qod_due_date = ? then qod_due_date = qo_due_date.
      if qod_req_date = ? then qod_req_date = qo_req_date.
      if qod_per_date = ? then qod_per_date = promise_date.
      if not can-find(first rsn_ref where rsn_code = qod_rsn_lost
                                      and rsn_type = "QUOTE")
      then
         qod_rsn_lost = rsn_lost.
   end.

   /* FIND LAST LINE */
   line = 0.

   find last pih_hist where pih_doc_type = 2 and
                            pih_nbr      = qo_mstr.qo_nbr
   use-index pih_nbr no-lock no-error.

   if available pih_hist then
      line = pih_line.
   else do:
      for each qod_det where qod_nbr = qo_nbr by qod_line descending:
         line = qod_line.
         leave.
      end.
   end.

   /* COMMENTS */
   global_type = "".
   global_lang = qo_lang.
   if qocmmts = yes then do:
      cmtindx = qo_cmtindx.
      global_ref = qo_cust.
      {gprun.i ""gpcmmt01.p"" "(input ""qo_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

      qo_cmtindx = cmtindx.
   end.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
   /* TRANSACTION */
